﻿Imports System.Data.SqlClient
Imports System.Xml
Imports System.IO
Imports Microsoft.VisualBasic

Public Class FormMain

    Private MySol As MsSqlToNhibCS = Nothing

    Private Sub OpenProjectToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OpenProjectToolStripMenuItem.Click
        Dim dlg As New OpenFileDialog
        dlg.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        dlg.Title = "Save Project"
        dlg.Filter = "SimpleGen Projects|*.sgp|All Files|*.*"
        dlg.CheckFileExists = True
        If Not dlg.ShowDialog() = DialogResult.OK Then Exit Sub
        Me.MySol = MsSqlToNhibCS.GetFtomFile(dlg.FileName)
        Me.Text = "SimpleGen [" & MySol.Name & "]"
    End Sub

    Private Sub NewProjectToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles NewProjectToolStripMenuItem.Click
        Dim Name As String = InputBox("Enter Project Name", My.Application.Info.ProductName)
        If String.IsNullOrEmpty(Name) Then
            MessageBox.Show("Invalid name.")
            Exit Sub
        Else
            Me.MySol = New MsSqlToNhibCS(Name)
            Me.Text = "SimpleGen [" & MySol.Name & "]"
        End If
    End Sub

    Private Sub SaveToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        If Me.MySol IsNot Nothing Then
            MySol.Save()
        End If
    End Sub

    Private Sub ExitToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        End
    End Sub

    Private Sub OptionsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles OptionsToolStripMenuItem.Click
        Dim f As New FormSettings
        f.ShowDialog()
    End Sub

    Private Sub RunToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles RunToolStripMenuItem1.Click
        If Me.MySol Is Nothing Then
            MessageBox.Show("No project.")
            Exit Sub
        End If

        Me.MySol.run()
    End Sub

    Private Sub SettingsToolStripMenuItem1_Click(sender As System.Object, e As System.EventArgs) Handles SettingsToolStripMenuItem1.Click
        If Not Me.MySol Is Nothing Then Me.MySol.ShowProperties()
    End Sub

    Private Sub AboutToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles AboutToolStripMenuItem.Click
        Dim f As New AboutBoxMain
        f.ShowDialog()
    End Sub

End Class
